package com.softline.documentsmall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.softline.documentsmall.dao.DictionaryShareMapper;
import com.softline.documentsmall.entity.DictionaryShare;
import com.softline.documentsmall.service.DictionaryShareService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @program: documentsmall
 * @description:
 * @author: wmj
 * @create: 2020-12-10
 * @ClassName: DictionaryShareServiceImpl
 */
@Service
@Slf4j
public class DictionaryShareServiceImpl extends ServiceImpl<DictionaryShareMapper, DictionaryShare> implements DictionaryShareService {

    @Override
    public void add(DictionaryShare dictionaryShare) {
        QueryWrapper<DictionaryShare> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("passport_id",dictionaryShare.getPassportId());
        queryWrapper.eq("dictionary_id",dictionaryShare.getDictionaryId());
        DictionaryShare one = this.getOne(queryWrapper);
        if (one == null){
            //新增分享记录
            this.save(dictionaryShare);
        }else {
            //分享记录+1
            Integer shareTimes = one.getShareTimes();
            one.setUpdateTime(new Date());
            shareTimes++;
            one.setShareTimes(shareTimes);
            this.updateById(one);
        }
    }
}
